package o;

import android.graphics.drawable.Drawable;
import androidx.annotation.GuardedBy;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.bumptech.glide.load.engine.GlideException;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class zk<R> implements zl<R>, zn<R> {
    private static final a ˎ = new a();
    @GuardedBy("this")
    private boolean ʻ;
    @GuardedBy("this")
    private boolean ʼ;
    @GuardedBy("this")
    private boolean ʽ;
    private final a ˊ;
    private final int ˋ;
    private final boolean ˏ;
    @GuardedBy("this")
    @Nullable
    private GlideException ˏॱ;
    private final int ॱ;
    @GuardedBy("this")
    @Nullable
    private R ॱॱ;
    @GuardedBy("this")
    @Nullable
    private zm ᐝ;

    @VisibleForTesting
    static class a {
        a() {
        }

        void ˎ(Object obj, long j) throws InterruptedException {
            obj.wait(j);
        }

        void ˎ(Object obj) {
            obj.notifyAll();
        }
    }

    public zk(int i, int i2) {
        this(i, i2, true, ˎ);
    }

    zk(int i, int i2, boolean z, a aVar) {
        this.ॱ = i;
        this.ˋ = i2;
        this.ˏ = z;
        this.ˊ = aVar;
    }

    public boolean cancel(boolean z) {
        zm zmVar = null;
        boolean z2 = true;
        synchronized (this) {
            if (isDone()) {
                z2 = false;
            } else {
                this.ʽ = true;
                this.ˊ.ˎ(this);
                if (z) {
                    zmVar = this.ᐝ;
                    this.ᐝ = null;
                }
                if (zmVar != null) {
                    zmVar.ॱ();
                }
            }
        }
        return z2;
    }

    public synchronized boolean isCancelled() {
        return this.ʽ;
    }

    public synchronized boolean isDone() {
        boolean z;
        z = this.ʽ || this.ʼ || this.ʻ;
        return z;
    }

    public R get() throws InterruptedException, ExecutionException {
        try {
            return ˏ(null);
        } catch (TimeoutException e) {
            throw new AssertionError(e);
        }
    }

    public R get(long j, @NonNull TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException {
        return ˏ(Long.valueOf(timeUnit.toMillis(j)));
    }

    public void getSize(@NonNull aaa o_aaa) {
        o_aaa.ˊ(this.ॱ, this.ˋ);
    }

    public void removeCallback(@NonNull aaa o_aaa) {
    }

    public synchronized void setRequest(@Nullable zm zmVar) {
        this.ᐝ = zmVar;
    }

    @Nullable
    public synchronized zm getRequest() {
        return this.ᐝ;
    }

    public void onLoadCleared(@Nullable Drawable drawable) {
    }

    public void onLoadStarted(@Nullable Drawable drawable) {
    }

    public synchronized void onLoadFailed(@Nullable Drawable drawable) {
    }

    public synchronized void onResourceReady(@NonNull R r, @Nullable aaf<? super R> o_aaf__super_R) {
    }

    private synchronized R ˏ(Long l) throws ExecutionException, InterruptedException, TimeoutException {
        R r;
        if (this.ˏ && !isDone()) {
            aau.ˊ();
        }
        if (this.ʽ) {
            throw new CancellationException();
        } else if (this.ʻ) {
            throw new ExecutionException(this.ˏॱ);
        } else if (this.ʼ) {
            r = this.ॱॱ;
        } else {
            if (l == null) {
                this.ˊ.ˎ(this, 0);
            } else if (l.longValue() > 0) {
                long currentTimeMillis = System.currentTimeMillis();
                long longValue = l.longValue() + currentTimeMillis;
                while (!isDone() && currentTimeMillis < longValue) {
                    this.ˊ.ˎ(this, longValue - currentTimeMillis);
                    currentTimeMillis = System.currentTimeMillis();
                }
            }
            if (Thread.interrupted()) {
                throw new InterruptedException();
            } else if (this.ʻ) {
                throw new ExecutionException(this.ˏॱ);
            } else if (this.ʽ) {
                throw new CancellationException();
            } else if (this.ʼ) {
                r = this.ॱॱ;
            } else {
                throw new TimeoutException();
            }
        }
        return r;
    }

    public void onStart() {
    }

    public void onStop() {
    }

    public void onDestroy() {
    }

    public synchronized boolean ॱ(@Nullable GlideException glideException, Object obj, zz<R> zzVar, boolean z) {
        this.ʻ = true;
        this.ˏॱ = glideException;
        this.ˊ.ˎ(this);
        return false;
    }

    public synchronized boolean ˎ(R r, Object obj, zz<R> zzVar, rz rzVar, boolean z) {
        this.ʼ = true;
        this.ॱॱ = r;
        this.ˊ.ˎ(this);
        return false;
    }
}
